package com.naiterui.ehp.ps.sms.dao.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import com.naiterui.ehp.ps.sms.bean.Platform;
import com.naiterui.ehp.ps.sms.dao.IPlatformDao;
import com.naiterui.ehp.ps.sms.repository.IPlatformRepository;
import com.naiterui.ehp.ps.sms.utils.constants.SmsConstants;

import lombok.RequiredArgsConstructor;

/**
 * 短信平台持久化实现
 *
 * @author
 * @since 1.0.0
 */
@Component
@RequiredArgsConstructor
public class PlatformDaoImpl implements IPlatformDao {

    private final IPlatformRepository platformRepository;

    @Override
    public List<Platform> getAll() {
        return platformRepository.findAll();
    }

    @Override
    public Platform getCurrentPlatform() {
        return platformRepository.findFirstByStatus(SmsConstants.EFFECTIVE_STAUTS);
    }

    @Override
    public Platform get(Integer id) {
        return platformRepository.get(id);
    }

    @Override
    public void saveOrUpdate(Platform platform) {
        if (platform.getId() == null) {
            platformRepository.save(platform);
        } else {
            platformRepository.update(platform);
        }
    }
}
